// FileObject.cpp : implementation file
//

#include "stdafx.h"
#include "BurnCD.h"
#include "FileObject.h"

#define SECTOR_SIZE	2048

// CFileObject
IMPLEMENT_DYNAMIC(CFileObject, CBaseObject)

CFileObject::CFileObject(const CString& filePath)
: CBaseObject(filePath)
, m_pStream(NULL)
{
}

CFileObject::~CFileObject()
{
    if (m_pStream != NULL)
        m_pStream->Release();
}


// CFileObject member functions
#include <sys\types.h> 
#include <sys\stat.h>
ULONGLONG CFileObject::GetSizeOnDisc()
{
//    CFileStatus status;
//    if (CFile::GetStatus(m_path, status))
//    {
//        if (status.m_size > 0)
//        {
//            return ((status.m_size / SECTOR_SIZE) + 1) * SECTOR_SIZE;
//        }
//    }
//
//    return 0;
	struct _stati64 fileStat; 
	int err = _stati64( (const char*)m_path.GetBuffer(0), &fileStat ); 
	if (0 != err) return 0; 
	return fileStat.st_size; 
}


IStream* CFileObject::GetStream()
{
	USES_CONVERSION;
	CString fileW;
	fileW.Format("\\\\?\\%s", m_path);
	
    if (m_pStream == NULL)
    {
		SHCreateStreamOnFileEx(A2CW(m_path.GetBuffer(0)), 
            STGM_READ|STGM_SHARE_DENY_NONE|STGM_DELETEONRELEASE,
            FILE_ATTRIBUTE_NORMAL, 
            FALSE, 
            NULL, 
            &m_pStream);
    }

    return m_pStream;
}

